package com.oops.controller;


import com.oops.RabbitMQConstants;
import com.oops.core.RabbitMQSender;
import com.oops.model.bo.OrderBo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Random;
import java.util.UUID;

@RestController
@RequestMapping(value = "/order")
@Slf4j
public class RabbitmqController {
    private RabbitMQSender sender;

    public RabbitmqController(RabbitMQSender sender) {
        this.sender = sender;
    }

    private static Random random = new Random(100000);


    @RequestMapping(value = "/{name}", method = RequestMethod.GET)
    public String order(@PathVariable("name") String name) {
        final OrderBo orderBo = new OrderBo();
        orderBo.setId(random.nextLong());
        orderBo.setProduct_id(random.nextLong());
        orderBo.setNum(100);
        orderBo.setProduct_name(name);
        orderBo.setCreateTime(LocalDateTime.now());

        sender.send(RabbitMQConstants.ORDER_BIZ_EXCHANGE_NAME, RabbitMQConstants.ORDER_BIZ_ROUTING_KEY, orderBo);
        return "ok";
    }

}